/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lenovo
 * Date: 2025-08-22
 * Time: 18:53
 */
//https://leetcode.cn/problems/find-pivot-index/submissions/655581222/
public class Test {
    public static int pivotIndex(int[] arr) {
        int size=arr.length;
        long sum=0;
        for(int i=0;i<size;i++){
            sum+=arr[i];
        }
        if(arr[0]==sum){
            return 0;
        }
        long n=arr[0];
        for(int i=1;i<size;i++){
            n+=arr[i];
            if(sum-n==n-arr[i]){
                return i;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        int[] arr={1,7,3,6,5,6};
        System.out.println(pivotIndex(arr));
    }
}
